#include "ToolBoxView.h"
#include "lvgl/lvgl.h"

// 图片资源
extern "C" {
	LV_IMG_DECLARE(ui_img_toolbox_finess_png);
	LV_IMG_DECLARE(ui_img_toolbox_weather_png);
	LV_IMG_DECLARE(ui_img_toolbox_training_png);
	LV_IMG_DECLARE(ui_img_toolbox_sunrise_png);
	LV_IMG_DECLARE(ui_img_toolbox_stopwatch_png);
	LV_IMG_DECLARE(ui_img_toolbox_steps_png);
	LV_IMG_DECLARE(ui_img_toolbox_solar_png);
	LV_IMG_DECLARE(ui_img_toolbox_sleep_png);
	LV_IMG_DECLARE(ui_img_toolbox_resources_png);
	LV_IMG_DECLARE(ui_img_toolbox_recovery_png);
	LV_IMG_DECLARE(ui_img_toolbox_progress_png);
	LV_IMG_DECLARE(ui_img_toolbox_oxygen_png);
	LV_IMG_DECLARE(ui_img_toolbox_notification_png);
	LV_IMG_DECLARE(ui_img_toolbox_media_png);
	LV_IMG_DECLARE(ui_img_toolbox_map_png);
	LV_IMG_DECLARE(ui_img_toolbox_logbook_png);
	LV_IMG_DECLARE(ui_img_toolbox_heart_rate_png);
	LV_IMG_DECLARE(ui_img_toolbox_compass_png);
	LV_IMG_DECLARE(ui_img_toolbox_alti_png);
}

ToolBoxView::ToolBoxView() :m_items{
	&ui_img_toolbox_finess_png,& ui_img_toolbox_weather_png, & ui_img_toolbox_training_png, & ui_img_toolbox_sunrise_png,
	& ui_img_toolbox_stopwatch_png,& ui_img_toolbox_steps_png,& ui_img_toolbox_solar_png,& ui_img_toolbox_sleep_png,
	& ui_img_toolbox_resources_png,& ui_img_toolbox_recovery_png,& ui_img_toolbox_progress_png ,& ui_img_toolbox_oxygen_png,
	& ui_img_toolbox_notification_png,& ui_img_toolbox_media_png,& ui_img_toolbox_map_png,& ui_img_toolbox_logbook_png,
	& ui_img_toolbox_heart_rate_png,& ui_img_toolbox_compass_png,& ui_img_toolbox_alti_png}
{
}

void ToolBoxView::Create(lv_obj_t* body) {
	
	// 标签容器
	lv_obj_t* div_label = lv_obj_create(body);
	lv_obj_set_size(div_label, 240, 40);
	lv_obj_set_pos(div_label, 0, -182);

	lv_obj_set_align(div_label, LV_ALIGN_CENTER);
	lv_obj_set_style_bg_opa(div_label, 0, 0);
	
	lv_obj_clear_flag(div_label, LV_OBJ_FLAG_SCROLLABLE);
	lv_obj_set_style_text_font(div_label, &lv_font_montserrat_24, LV_PART_MAIN | LV_STATE_DEFAULT);
	lv_obj_set_style_text_color(div_label, lv_color_white(), 0);

	// 标签
	lv_obj_t* label = lv_label_create(div_label);
	lv_obj_set_size(label, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
	lv_obj_set_align(label, LV_ALIGN_CENTER);
	lv_label_set_text(label, "Tools Box");

	CreateMenu(body);
}

void ToolBoxView::CreateMenu(lv_obj_t* parent) {

	// menu容器
	lv_obj_t* div = lv_obj_create(parent);
	lv_obj_set_size(div, 240, 398);
	lv_obj_set_pos(div, 0, 35);
	lv_obj_set_align(div, LV_ALIGN_CENTER);
	lv_obj_set_scroll_dir(div, LV_DIR_VER);
	lv_obj_set_style_bg_opa(div, 8, LV_PART_MAIN);

	// 设置滚动条样式
	lv_obj_set_style_width(div, 6, LV_PART_SCROLLBAR);
	lv_obj_set_style_radius(div, 3, LV_PART_SCROLLBAR); // 圆角
	lv_obj_set_style_bg_color(div, lv_color_hex(0x101418), LV_PART_SCROLLBAR);
	
	// 创建子项
	uint32_t item_h = 100;
	for (uint8_t i = 0; i < sizeof(m_items) / sizeof(lv_img_dsc_t); i++)
	{
		lv_obj_t* item = lv_obj_create(div);
		lv_obj_set_size(item, 240, item_h);
		lv_obj_set_pos(item, 0, -148 + i* item_h);
		lv_obj_set_align(item, LV_ALIGN_CENTER);
		lv_obj_set_style_bg_img_src(item, m_items[i], LV_PART_MAIN);
		lv_obj_set_style_bg_opa(item, 0, LV_PART_MAIN);
		lv_obj_clear_flag(item, LV_OBJ_FLAG_SCROLLABLE);
	}

	// 	lv_obj_set_style_outline_width(div_label, 2, 0);
	// 	lv_obj_set_style_outline_color(div_label, lv_color_white(), 0);
}